package com.example.demo.utils;

import com.fasterxml.jackson.annotation.JsonInclude;

import java.io.Serializable;

/**
 * Result生成工具，快速创建Result对象
 */
public class Result  implements Serializable {

    private static final long serialVersionUID = 1430633339880116031L;

    /*
    * 成功与否标志
    * */
    private boolean success = true;
    /*
    * 返回状态码，为空则默认为200,前端需要拦截一些常见的状态吗如403、404、500等
    * */
    @JsonInclude(JsonInclude.Include.NON_NULL)
    private Integer status;
    /*
    * 编码：可以用于前端处理多语言，不需要则不返回编码
    * */
    @JsonInclude(JsonInclude.Include.NON_NULL)
    private String code;
    /*
    * 相关消息
    * */
    @JsonInclude(JsonInclude.Include.NON_NULL)
    private String msg;
    /*
    * 相关数据
    * */
    @JsonInclude(JsonInclude.Include.NON_NULL)
    private Object data;

    public Result(){}

    public Result(Boolean success){
        this.success = success;
    }

    public Result(Boolean success,Integer status){
        this.success = success;
        this.status = status;
    }

    public Result(Boolean success,String code,String msg){
        this(success);
        this.code = code;
        this.msg = msg;
    }

    public Result(Boolean success,Integer status,String code,String msg){
        this.success = success;
        this.status = status;
        this.code = code;
        this.msg = msg;
    }

    public Result(Boolean success,Integer status,Object data,String msg){
        this.success = success;
        this.status = status;
        this.data = data;
        this.msg = msg;
    }
    public Result(Boolean success,String code,String msg,Object data){
        this.success = success;
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public Integer getStatus() {
        return status;
    }

    public void setStatus(Integer status) {
        this.status = status;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }
}
